package com.banana.manager.forest.service.impl.handle;

import com.banana.manager.forest.dao.handle.IRecordDao;
import com.banana.manager.forest.entity.handle.AreaBean;
import com.banana.manager.forest.entity.handle.RecordBean;
import com.banana.manager.forest.service.iihandle.IRecordService;
import com.banana.manager.forest.util.PageInfoSize;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.time.LocalDate;
@Service
@Transactional
public class RecordServiceImpl implements IRecordService {
    @Resource
    private IRecordDao recordDao;

    @Override
    public RecordBean addRecord( RecordBean recordBean) {
        System.out.println(recordBean);
        recordDao.insert(recordBean);
        return recordDao.selectById(recordBean.getRecordId());
    }

    @Override
    public RecordBean findById(Integer id) {
        return recordDao.findOneById(id);
    }

    @Override
    public RecordBean modifyStageAndMeasure( RecordBean recordBean) {
        System.out.println(recordBean);
        recordDao.updateById(recordBean);
        return recordDao.selectById(recordBean.getRecordId());
    }

    @Override
    public void askPhdHelp(Integer id) {
        RecordBean recordBean = recordDao.selectById(id);
        recordBean.setRecordStage("无法解决，申请专家会商");
        recordDao.updateById(recordBean);
    }

    @Override
    public PageInfo<RecordBean> findBlurByPage(Integer page, String recordName, String recordStage, String recordArea, LocalDate start, LocalDate end) {
        String recordNameNew = "%"+recordName+"%";
        String recordStageNew = "%"+recordStage+"%";
        String recordLocationNew = "%"+recordArea+"%";

        QueryWrapper<RecordBean> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("record_name",recordNameNew);
        queryWrapper.like("record_stage",recordStageNew);
        queryWrapper.like("record_area",recordLocationNew);
        queryWrapper.ge("record_date",start);
        queryWrapper.le("record_date",end);
        PageHelper.startPage(page, PageInfoSize.pageSize);
        return PageInfo.of(recordDao.selectList(queryWrapper));
    }


}
